package com.buptse.service;

import com.buptse.dao.UserMapper;
import com.buptse.model.User;
import com.buptse.model.UserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    //login
    public Map<String,Object> login(String account,String password){
        Map<String,Object> result=new HashMap<>();
        UserExample userExample=new UserExample();
        userExample.createCriteria().andAccountEqualTo(account);
        List<User> userList=userMapper.selectByExample(userExample);
        if(userList.isEmpty()==true){
            result.put("result","account not exist");
        }else{
            if(userList.get(0).getPassword().equals(password)==true){
                result.put("result","login successfully");
            }else{
                result.put("result","password error");
            }
        }
        return result;
    }

}
